﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YetiManagement
{
    public partial class Logs : System.Web.UI.Page
    {


        public int IdSession
        {
            get
            {
                if (this.ViewState["IdSession"] == null)
                {
                    this.ViewState["IdSession"] = 0;
                }
                return (int)(this.ViewState["IdSession"]);
            }
            set { this.ViewState["IdSession"] = value; }

        }   


        protected void Page_Load(object sender, EventArgs e)
        {
            labelka.Text = "";
        }

        protected void SessionsGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
           
            GridView sendingGridView = (GridView)sender;
            int idSession = Convert.ToInt32(sendingGridView.SelectedDataKey["ID_session"].ToString());

            IdSession = idSession;
            TurnsSource.SelectCommand =
                "SELECT t.ID_turn,p.[ID_pattern], p.[Content] AS PatternContent,r.[ID_response], r.[Content] AS ResponseContent " +
                "FROM Pattern AS p INNER JOIN Turn AS t ON p.ID_pattern = t.ID_pattern INNER JOIN Response AS r " +
                "ON t.ID_response = r.ID_response AND p.ID_pattern = r.ID_pattern INNER JOIN Session AS s ON t.ID_session = s.ID_session WHERE (s.ID_session = " + idSession + ")";
            GridViewTurns.DataBind();
    
        }

        //protected void GridViewTurns_RowUpdating(object sender, GridViewUpdateEventArgs e)
        //{
        //  //  TurnsSource.UpdateCommand = "UPDATE Pattern SET Content = @PatternContent WHERE ID_pattern = @ID_pattern  UPDATE Response SET Content = @ResponseContent WHERE ID_content = @ID_content";

        //    //"SELECT t.ID_turn, p.[Content] AS PatternContent, r.[Content] AS ResponseContent " +
        //    //   "FROM Pattern AS p INNER JOIN Turn AS t ON p.ID_pattern = t.ID_pattern INNER JOIN Response AS r " +
        //    //   "ON t.ID_response = r.ID_response AND p.ID_pattern = r.ID_pattern INNER JOIN Session AS s ON t.ID_session = s.ID_session WHERE (s.ID_session = " + IdSession + ")";
        //    ////GridViewTurns.UpdateRow();
        //  //  TurnsSource.Update();

        //}

        protected void SessionsGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            { 
                switch (e.Row.Cells[2].Text)
                {
                    case "Ok":
                        e.Row.ForeColor = Color.Green;
                        //e.Row.BackColor = Color.Green;
                        break;
                    case "&nbsp;":
                        e.Row.ForeColor = Color.Red;
                        //e.Row.BackColor = Color.Blue;
                        break;
                    
                }
            }
        }

        protected void GridViewTurns_RowEditing(object sender, GridViewEditEventArgs e)
        {

            TurnsSource.SelectCommand =
               "SELECT t.ID_turn,p.[ID_pattern], p.[Content] AS PatternContent,r.[ID_response], r.[Content] AS ResponseContent " +
               "FROM Pattern AS p INNER JOIN Turn AS t ON p.ID_pattern = t.ID_pattern INNER JOIN Response AS r " +
               "ON t.ID_response = r.ID_response AND p.ID_pattern = r.ID_pattern INNER JOIN Session AS s ON t.ID_session = s.ID_session WHERE (s.ID_session = " + IdSession + ")";
            GridViewTurns.DataBind();

        }

       
    }
}